package com.teamclub.erp.scontrollers

import io.ebean.Ebean
import com.teamclub.domain.system.AppDomainInstance
import com.teamclub.pay.sforms.PayOrderForm
import com.teamclub.pay.sservices.OrderService
import com.teamclub.util.libs.Eithers
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.{PostMapping, RequestMapping, RestController}

@RestController("com.teamclub.erp.scontrollers.ErpOrderController")
@RequestMapping(Array("/erp/order"))
class ErpOrderController {
  @Autowired
  var orderService: OrderService = _

  @PostMapping(Array("list"))
  def list(form: PayOrderForm) = {
    val instance = Ebean.find(classOf[AppDomainInstance]).where().eq("appDomain", "WINDER-MANAGER").findOne()
    form.setOrganNo(instance.getOrganNo)
    Eithers.toJson(orderService.list(form))
  }
}
